package Draw0513;

import java.awt.*;
import java.util.ArrayList;

public class PolygonShape extends ShapeV2{
    ArrayList<Point> points = new ArrayList<>();
    public PolygonShape(){

    }

    public PolygonShape(Point p1, Point p2, Color color){
        points.add(p1);
        points.add(p2);
        this.color = color;
    }

    public PolygonShape(Point p1, Point p2, Point p3, Color color){
        points.add(p1);
        points.add(p2);
        points.add(p3);
        this.color = color;
    }


    @Override
    public void drawShapeV2(Graphics g) {
        g.setColor(color);
        if (points.size() == 2){
            Point p1 = points.get(0);
            Point p2 = points.get(1);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);

        } else if (points.size() == 3) {
            Point p1 = points.get(0);
            Point p2 = points.get(1);
            Point p3 = points.get(2);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);
            g.drawLine(p1.x, p1.y, p3.x, p3.y);
            g.drawLine(p3.x, p3.y, p2.x, p2.y);
        } else if (points.size() > 3){
            for (int i = 0; i < points.size() - 1; i++) {
                Point p1 = points.get(i);
                Point p2 = points.get(i + 1);
                g.drawLine(p1.x, p1.y, p2.x, p2.y);
            }
            Point p0 = points.get(0);
            Point pn = points.get(points.size() - 1);
            g.drawLine(p0.x, p0.y, pn.x, pn.y);
        }
    }
}
